/************ JunrLi_sbus control ************/
#ifndef REMOTE_CONTROL_H
#define REMOTE_CONTROL_H

#include "bsp_rc.h"

#define SBUS_RX_BUF_NUM 36u

#define RC_FRAME_LENGTH 25u

#define RC_CH_VALUE_OFFSET 1024U

extern uint8_t SBUS_MultiRx_Buf[2][RC_FRAME_LENGTH];

#define RC_SW_UP                ((uint16_t)1541)
#define RC_SW_MID               ((uint16_t)1024)
#define RC_SW_DOWN              ((uint16_t)511)
#define switch_is_down(s)       (s == RC_SW_DOW)
#define switch_is_mid(s)        (s == RC_SW_MID)
#define switch_is_up(s)         (s == RC_SW_UP)

//left
#define IF_RC_SW2_UP (rc_ctrl.rc.ch[5]==RC_SW_UP)
#define IF_RC_SW2_MID (rc_ctrl.rc.ch[5]==RC_SW_MID)
#define IF_RC_SW2_DOWN (rc_ctrl.rc.ch[5]==RC_SW_DOWN)

//right
#define IF_RC_SW1_UP (rc_ctrl.rc.ch[6]==RC_SW_UP)
#define IF_RC_SW1_MID (rc_ctrl.rc.ch[6]==RC_SW_MID)
#define IF_RC_SW1_DOWN (rc_ctrl.rc.ch[6]==RC_SW_DOWN)

typedef __packed struct
{
    __packed struct
    {
        int16_t ch[18];
    } rc;
} RC_ctrl_t;

extern RC_ctrl_t rc_ctrl;

void SBUS_TO_RC(volatile const uint8_t *sbus_buf, RC_ctrl_t *sbus_ctrl);

#endif

